package com.vcs.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;
import com.vcs.domain.Client;
import com.vcs.domain.Country;
import com.vcs.domain.Function;
import com.vcs.domain.FunctionalArea;
import com.vcs.domain.Industry;
import com.vcs.domain.Location;
import com.vcs.domain.Qualification;
import com.vcs.domain.State;
import com.vcs.util.HibernateUtil;

public class UtilDAOImpl implements UtilDAO {

	Log log = LogFactory.getLog(UtilDAOImpl.class);

	public UtilDAOImpl() {
		session = HibernateUtil.getSessionFactory().openSession();
		transaction = session.beginTransaction();
	}
	
	
	// @SessionTarget
	Session session;

	// @TransactionTarget
	Transaction transaction;

	@Override
	public List<Country> getCountryList() {
		log.info("Entered getCountryList method");
		System.out.println("Entered getCountryList method");
		List<Country> countryList = null;
		try {
			countryList = session.createQuery("from Country").list();
		} catch (Exception e) {
			e.printStackTrace();
		}
		log.info("countryList is : " + countryList);
		System.out.println("countryList is : " + countryList);
		return countryList;
	}

	@Override
	public String getCountryById(int countryId) {
		Country country = null;
		try {
			country = (Country) session.get(Country.class, countryId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return country.getCountryName();
	}

	@Override
	public List<Location> getLocationList() {
		List<Location> locationList = null;
		try {
			locationList = session.createQuery("from Location").list();
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("locationList : " + locationList);
		return locationList;
	}

	@Override
	public String getLocationById(int locationId) {
		Location location = null;
		try {
			location = (Location) session.get(Location.class, locationId);
			System.out.println("location " + location);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return location.getName();
	}

	@Override
	public String getIndustryById(int industryId) {
		Industry industry = null;
		try {
			industry = (Industry) session.get(Industry.class, industryId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return industry.getName();
	}

	@Override
	public List<Industry> getIndustryList() {
		log.info("Entered getIndustryList method");

		List<Industry> industryList = null;
		try {
			industryList = session.createQuery("from Industry").list();
		} catch (Exception e) {
			e.printStackTrace();
		}
		log.info("countryList is : " + industryList);
		System.out.println("industryList is : " + industryList);
		return industryList;
	}

	@Override
	public String getFunctionById(int functionId) {
		Function function = null;
		try {
			function = (Function) session.get(Function.class, functionId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return function.getFunctionName();
	}

	@Override
	public List<Function> getFunctionList() {
		List<Function> functionList = null;
		try {
			functionList = session.createQuery("from Function").list();
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("Function List --> " + functionList);
		return functionList;
	}

	@Override
	public List<State> getStateList() {
		List<State> stateList = null;
		try {
			stateList = session.createQuery("from State").list();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return stateList;
	}

	@Override
	public String getStateById(int id) {
		State state = null;
		try {
			state = (State) session.get(State.class, id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return state.getName();
	}

	@Override
	public List<FunctionalArea> getFuncationalAreaList() {
		List<FunctionalArea> funcAreaList = null;
		try {
			funcAreaList = session.createQuery("from FunctionalArea").list();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return funcAreaList;
	}

	@Override
	public String getFunctionalAreaById(int id) {
		FunctionalArea funcArea = null;
		try {
			funcArea = (FunctionalArea) session.get(FunctionalArea.class, id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return funcArea.getName();
	}

	@Override
	public List<Qualification> getQualificationList() {
		List<Qualification> qualificationList = null;
		try {
			qualificationList = session.createQuery("from Qualification").list();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return qualificationList;
	}

	@Override
	public String getQualificationById(int id) {
		Qualification qualification = null;
		try {
			qualification = (Qualification) session.get(Qualification.class, id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return qualification.getName();
	}

	@Override
	public String getContent(String contentIdConstant) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setContent(String contentIdConstant, String content) {
		// TODO Auto-generated method stub
		
	}

}
